levelbar: don't use the current value style class for empty blocks
authorCosimo Cecchi <cosimoc@gnome.org>
Fri, 24 Oct 2014 22:25:36 +0000 (15:25 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 27 Oct 2014 10:56:19 +0000 (06:56 -0400)
We want to be able to style the empty blocks independently of all the
offset styles, so remove the current style class when painting an empty
block.

https://bugzilla.gnome.org/show_bug.cgi?id=707695

gtk/gtklevelbar.c

index f8b234c582a1d5873cd91ac6e1d7f5423e33c7c5..8f6b97c367645326603a2498953a6afa588b962c 100644 (file)
@@ -150,6 +150,8 @@ struct _GtkLevelBarPrivate {
 
   GList *offsets;
 
+  gchar *cur_value_class;
+
   guint inverted : 1;
 };
 
@@ -336,6 +338,8 @@ gtk_level_bar_draw_fill_continuous (GtkLevelBar           *self,
   base_area.width -= block_margin.left + block_margin.right;
   base_area.height -= block_margin.top + block_margin.bottom;
 
+  if (self->priv->cur_value_class)
+    gtk_style_context_remove_class (context, self->priv->cur_value_class);
   gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);
 
   gtk_render_background (context, cr, base_area.x, base_area.y,
@@ -344,6 +348,8 @@ gtk_level_bar_draw_fill_continuous (GtkLevelBar           *self,
                     base_area.width, base_area.height);
 
   gtk_style_context_remove_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);
+  if (self->priv->cur_value_class)
+    gtk_style_context_add_class (context, self->priv->cur_value_class);
 
   /* now render the filled part on top of it */
   block_area = base_area;
@@ -442,7 +448,11 @@ gtk_level_bar_draw_fill_discrete (GtkLevelBar           *self,
         }
 
       if (idx > num_filled - 1)
-        gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);
+        {
+          gtk_style_context_add_class (context, STYLE_CLASS_EMPTY_FILL_BLOCK);
+          if (self->priv->cur_value_class != NULL)
+            gtk_style_context_remove_class (context, self->priv->cur_value_class);
+        }
 
       gtk_render_background (context, cr,
                              block_area.x, block_area.y,
@@ -635,10 +645,12 @@ gtk_level_bar_update_level_style_classes (GtkLevelBar *self)
         }
     }
 
+  g_clear_pointer (&self->priv->cur_value_class, g_free);
+
   if (value_class != NULL)
     {
       gtk_style_context_add_class (context, value_class);
-      g_free (value_class);
+      self->priv->cur_value_class = value_class;
     }
 }
 
@@ -884,6 +896,7 @@ gtk_level_bar_finalize (GObject *obj)
   GtkLevelBar *self = GTK_LEVEL_BAR (obj);
 
   g_list_free_full (self->priv->offsets, (GDestroyNotify) gtk_level_bar_offset_free);
+  g_free (self->priv->cur_value_class);
 
   G_OBJECT_CLASS (gtk_level_bar_parent_class)->finalize (obj);
 }